Skilled in SEO, content writing, and digital marketing. Completed several years of working in many organizations including multinational companies. I love to learn new things in life that keep me motivated.
In HTML, `cellpadding` and `cellspacing` are attributes that are used to control the spacing between table cells. However, they are not CSS properties and cannot be set using CSS.
Instead, you can use CSS to control the spacing between table cells by setting the `border-spacing` or `border-collapse` properties on the table element. Here's an example:
table {
border-spacing: 10px; /* Set the spacing between cells */
border-collapse: separate; /* Make sure the borders between cells are visible */
}
In this example, we're setting the `border-spacing` property to `10px`, which will create a 10-pixel gap between adjacent cells in the table. We're also setting the `border-collapse` property to `separate`, which ensures that the borders between cells are visible.
Note that `border-spacing` is a shorthand property for setting both the horizontal and vertical spacing between cells. If you need to set different horizontal and vertical spacing, you can use the `border-spacing` property with two values, like this:
table {
border-spacing: 10px 5px; /* Set 10 pixels horizontal spacing and 5 pixels vertical spacing */
border-collapse: separate;
}
Again, note that `cellpadding` and `cellspacing` are not CSS properties and cannot be set directly with CSS.
Liked By
Write Answer
Set cellpadding and cellspacing in CSS?
Join MindStick Community
You have need login or register for voting of answers or question.
Aryan Kumar
25-Apr-2023In HTML, `cellpadding` and `cellspacing` are attributes that are used to control the spacing between table cells. However, they are not CSS properties and cannot be set using CSS.
Instead, you can use CSS to control the spacing between table cells by setting the `border-spacing` or `border-collapse` properties on the table element. Here's an example:
In this example, we're setting the `border-spacing` property to `10px`, which will create a 10-pixel gap between adjacent cells in the table. We're also setting the `border-collapse` property to `separate`, which ensures that the borders between cells are visible.
Note that `border-spacing` is a shorthand property for setting both the horizontal and vertical spacing between cells. If you need to set different horizontal and vertical spacing, you can use the `border-spacing` property with two values, like this:
Again, note that `cellpadding` and `cellspacing` are not CSS properties and cannot be set directly with CSS.